<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="oid">
        <el-input
            v-model="queryParams.oid"
            placeholder="请输入订单编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="">
        <el-select v-model="queryParams.type" multiple placeholder="请选择">
          <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="">
        <el-select v-model="queryParams.orderstatus" multiple placeholder="请选择">
          <el-option
              v-for="item in options2"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付状态">
        <el-radio-group v-model="queryParams.paystatus">
          <el-radio :label="0">已支付</el-radio>
          <el-radio :label="1">待支付</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="订单时间"  prop="start,end">
        <el-date-picker clearable v-model="queryParams.payissuetime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :default-time="'00:00:00'" placeholder="开始时间"></el-date-picker>
        -
        <el-date-picker clearable v-model="queryParams.payarrivetime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :default-time="'23:59:59'" placeholder="结束时间"></el-date-picker>
      </el-form-item>
      <el-form-item >
        <el-input v-model="queryParams.abc" placeholder="请输入姓名、手机号、车牌号" clearable style="width:250px;"></el-input>
      </el-form-item>
      <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      <el-button type="primary" icon="el-icon-search" size="mini" @click="getList()">查询</el-button>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['orders:orderfrom:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['orders:orderfrom:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['orders:orderfrom:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['orders:orderfrom:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderfromList" @selection-change="handleSelectionChange" style="width: 110%;" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column fixed label="订单编号" align="center" prop="oid" />
      <el-table-column label="订单类型" align="center" prop="type"><template slot-scope="scope">
        {{scope.row.type == 0 ? '实时代叫车':scope.row.type == 1 ? '实时自叫车':scope.row.type == 2 ? '实时货运':scope.row.type == 3 ? '预约代叫车':scope.row.type == 4 ? '预约自叫车':scope.row.type == 5 ? '预约货运':''}}
      </template></el-table-column>
      <el-table-column label="用户名称" align="center" prop="real_name" />
      <el-table-column label="用户手机号" align="center" prop="phone" />
      <el-table-column label="乘客姓名" align="center" prop="real_name" />
      <el-table-column label="乘客手机号" align="center" prop="phone" />
      <el-table-column label="司机姓名" align="center" prop="name" />
      <el-table-column label="司机手机号" align="center" prop="tel" />
      <el-table-column label="司机车牌号" align="center" prop="license_plate_number" />
      <el-table-column label="订单出发地点" align="center" prop="starting" />
      <el-table-column label="途径点一" align="center" prop="routepointone" />
      <el-table-column label="途径点二" align="center" prop="routepointtwo" />
      <el-table-column label="订单目的地" align="center" prop="destination" />
      <el-table-column label="实际下车点" align="center" prop="getpoint" />
      <el-table-column label="订单发出时间" align="center" prop="payissuetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payissuetime, '{y}-{m}-{d}-{h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单预约时间" align="center" prop="paymaketime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.paymaketime, '{y}-{m}-{d}-{h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单到达时间" align="center" prop="payarrivetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payarrivetime, '{y}-{m}-{d}-{h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单里程" align="center" prop="mileage" />
      <el-table-column label="订单耗时" align="center" prop="payconsuming" />
      <el-table-column label="是否提前下车" align="center" prop="getoffcar">
        <template slot-scope="scope">
          {{scope.row.getoffcar === 0 ? '否':'是'}}
        </template>
      </el-table-column>
      <el-table-column label="乘客总费用" align="center" prop="pricesum" />
      <el-table-column fixed="right" label="订单状态" align="center" prop="orderstatus">
        <template slot-scope="scope">
          {{scope.row.orderstatus == 0 ? '已取消':scope.row.orderstatus == 1 ? '已完成':scope.row.orderstatus == 2 ? '进行中':scope.row.orderstatus == 3 ? '待接单':'路程中'}}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="支付状态" align="center" prop="paystatus">
        <template slot-scope="scope">
          {{scope.row.paystatus === 0 ? '已支付':'待支付'}}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="支付时间" align="center" prop="paytime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payissuetime, '{y}-{m}-{d}-{h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
          >费用详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改订单管理对话框 -->
  </div>
</template>

<script>


import { listOrderfrom, getOrderfrom, delOrderfrom, addOrderfrom, updateOrderfrom } from "@/api/orders/orderfrom";
// const valuesArray = Object.values(this.queryParams.starting)
// console.log(valuesArray)
export default {
  name: "Orderfrom",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单管理表格数据
      orderfromList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      // 查询参数
      ordersDetail:{},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        oid: null,
        //订单类型
        type:'',
        payissuetime: null,
        paymaketime: null,
        payarrivetime: null,
        //订单状态
        orderstatus: '',
        paystatus: null,
        paytime: null,
        abc:'',
      },
      options: [
        { value: 0, label: '实时代叫车' },
        { value: 1, label: '实时自叫车' },
        { value: 2, label: '实时货运' },
        { value: 3, label: '预约代叫车' },
        { value: 4, label: '预约自叫车' },
        { value: 5, label: '预约货运' }
      ],
      options2: [
        { value: 0, label: '已取消' },
        { value: 1, label: '已完成' },
        { value: 2, label: '进行中' },
        { value: 3, label: '待接单' },
        { value: 4, label: '路程中' },
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单管理列表 */
    getList() {
      this.loading = true;

      //将数组转换为字符串
      if (this.queryParams.type && this.queryParams.type.length > 0) {
        this.queryParams.type = this.queryParams.type.join(',');
      }
      if (this.queryParams.orderstatus && this.queryParams.orderstatus.length > 0) {
        this.queryParams.orderstatus = this.queryParams.orderstatus.join(',');
      }
      listOrderfrom(this.queryParams).then(response => {
        this.orderfromList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.queryParams.type = this.queryParams.type.split(',');
        this.queryParams.type = this.queryParams.type.map(item => parseInt(item));
        this.queryParams.orderstatus = this.queryParams.orderstatus.split(',');
        this.queryParams.orderstatus = this.queryParams.orderstatus.map(item => parseInt(item));
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        oid: null,
        type: '',
        payissuetime: null,
        paymaketime: null,
        payarrivetime: null,
        orderstatus: '',
        paystatus: null,
        paytime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.ordersDetail = row;
      this.$router.push({ path: "/jichugongneng/orderfrom/ordersfrom", query: { ordersDetail:this.ordersDetail } });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrderfrom(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderfrom(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单管理编号为"' + ids + '"的数据项？').then(function() {
        return delOrderfrom(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('orders/orderfrom/export', {
        ...this.queryParams
      }, `orderfrom_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
